package com.liuxu.NoRoot;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import java.util.HashMap;
import java.util.Map;

public class Service {
    public String updateinfo;
   private Server server=new Server();
    public void run(String vision, String action, String token, String id, Handler handler){
        Map topics= MyApplication.getTopics();
        String csrf_token =server.gettoken();
        Map values = new HashMap();
        values.put("token", token);
        values.put("id",id);
        values.put("version",vision);
        values.put("csrfmiddlewaretoken",csrf_token);
        String[] data=server.getideninfo(action,values);
        Message msg = Message.obtain();
        msg.obj = action+data[0]+","+data[1];
        handler.sendMessage(msg);
        if (data[0].equals("成功")&&action.equals("运行")){
            Message msg1 = Message.obtain();
            msg1.obj = data[2]+"会员，有效期至"+data[3];
            handler.sendMessage(msg1);
            MyApplication.permission=true;
        }
    }
    public void checkUpdate(String vision){
       String[] infos=server.getUpdateInfo();
       if (!infos[0].equals(vision)){
           MyApplication.update=true;
           Log.v("设置更新状态","有更新");
       }else{
           MyApplication.update=false;
           Log.v("设置更新状态","无更新");
       }
       if (infos[2].equals("true")){
           MyApplication.must=true;
           Log.v("设置更新状态","强制更新");
       }
        MyApplication.updateinfo=infos[1];
    }
}
